<?php
// +----------------------------------------------------------------------
// | Fanwe 方维订餐小秘书商业系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 云淡风轻(88522820@qq.com)
// +----------------------------------------------------------------------

class orderModule extends StoreBaseModule
{
	public function index()
	{
		$user_id = intval($GLOBALS['user_info']['id']);
		
		convert_req($_REQUEST);
		$id = intval($_REQUEST['id']);
		if($id==0){
			showErr($GLOBALS['lang']['NO_STORE_INFO']);
		}
		if($user_id==0)
		{
			set_gopreview();
			app_redirect(url("shop","user#login"));
		}
		$store_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."supplier_location where id = ".$id." and one_line_order = 1 and is_effect = 1");
		if(!$store_info)
		{
			showErr($GLOBALS['lang']['NO_STORE_INFO']);
		}
		
		$site_nav[] = array('name'=>$GLOBALS['lang']['HOME_PAGE'],'url'=>url("store","index"));
		if($store_info['deal_type'] == 1)
		{
			$store_info['url'] = url("store","kview",array("id"=>$id));
			$actionv = "kview";
			$ov = "ktv";
		}
		else{
			$store_info['url '] = url("store","view",array("id"=>$id));
			$actionv = "view";
			$ov = "ct";
		}
		$site_nav[] = array('name'=>$store_info['name'],'url'=>url("store",$actionv,array("id"=>$store_info['id'])));
		$site_nav[] = array('name'=>"我的订单",'url'=>url("index","uc_order#$ov"));
		$GLOBALS['tmpl']->assign("site_nav",$site_nav);
		$GLOBALS['tmpl']->assign("store_info",$store_info);
		
		$now_time = get_gmtime();
				
		$default_hour = to_date($now_time,"H");
		if((int)$default_hour > 9 && (int)$default_hour < 21){
			$default_hour = (int)$default_hour+1;
		}
		else{
			if(intval($default_hour) >21){
				$now_time = $now_time +(3600*3);
			}
			
			$default_hour = 10;
		}
		
		if(!empty($_REQUEST['orderDate'])){
			$default_date = trim($_REQUEST['orderDate']);
		}
		else{
			$week = array('日','一','二','三','四','五','六'); 
			$default_date = to_date($now_time,"Y年m月d日") ." 星期".$week[to_date($now_time,"w")];
		}
		
		if(!empty($_REQUEST['orderHour'])){
			$default_hour = trim($_REQUEST['orderHour']);
		}
		else{
			$default_hour = $default_hour."点";
		}
		
		
		$GLOBALS['tmpl']->assign("default_date",$default_date);
		$GLOBALS['tmpl']->assign("default_hour",$default_hour);
		
		if(!empty($_REQUEST['orderMini'])){
			$default_mini = trim($_REQUEST['orderMini']);
		}
		else{
			$default_mini = "15分";
		}
				
		$GLOBALS['tmpl']->assign("default_mini",$default_mini);
				
		$GLOBALS["tmpl"]->display("store_order.html");
	}
	
	public function submit(){
		convert_req($_REQUEST);
		foreach($_REQUEST as $k=>$v)
		{
			$_REQUEST[$k] = htmlspecialchars(addslashes(trim($v)));
		}
		$is_ajax = intval($_REQUEST['is_ajax']);
		$deal_type = intval($_REQUEST['deal_type']);
		if(!check_ipop_limit(get_client_ip(),"store_order",intval(app_conf("SUBMIT_DELAY")))){
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$GLOBALS['lang']['SUBMIT_TOO_FAST']));
			else
			{
				showErr($GLOBALS['lang']['SUBMIT_TOO_FAST']);
			}
		}
		$sid = intval($_REQUEST['sid']);
		$store = $GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."supplier_location WHERE one_line_order=1 AND id=".$sid);
		if($store <= 0){
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$GLOBALS['lang']['NO_STORE_INFO']));
			else
				showErr($GLOBALS['lang']['NO_STORE_INFO']);
		}
		$orderDate = trim($_REQUEST['orderDate']);
		if(empty($orderDate)){
			$tip ="就餐日期不能为空!";
			if($deal_type==1){
				$tip ="K歌日期不能为空!";
			}
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$tip));
			else
				showErr($tip);
		}
		$orderHour = trim($_REQUEST['orderHour']);
		if(empty($orderHour)){
			$tip ="我们需要知道您具体几点就餐!";
			if($deal_type==1){
				$tip ="我们需要知道您具体几点K歌!";
			}
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$tip));
			else
				showErr($tip);
		}
		$orderMini = trim($_REQUEST['orderMini']);
		if(empty($orderMini)){
			$tip ="我们需要知道您大致就餐分钟!";
			if($deal_type==1){
				$tip ="我们需要知道您大致K歌分钟!";
			}
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$tip));
			else
				showErr($tip);
		}
		$orderNums =  intval($_REQUEST['orderNums']);
		if($orderNums == 0)
		{
			$tip ="我们需要知道有几人就餐!";
			if($deal_type==1){
				$tip ="我们需要知道有几人K歌!";
			}
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$tip));
			else
				showErr($tip);
		}
		if(!isset($_REQUEST['seatStatus'])){
			$tip ="您还未选择您的座位要求!";
			if($deal_type==1){
				$tip ="您还未选择您的包厢要求!";
			}
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$tip));
			else
				showErr($tip);
		}
		
		$seatStatus = intval($_REQUEST['seatStatus']);
		$minExpense = trim($_REQUEST['minExpense']);
		$seatSwitch = intval($_REQUEST['seatSwitch']);
		
		$orderMyTel = trim($_REQUEST['orderMyTel']);
		
		if(empty($orderMyTel))
		{
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>"您好，我们需要知道您的手机号以方便联系您!"));
			else
				showErr("您好，我们需要知道您的手机号以方便联系您!");
		}
		elseif(!check_mobile($orderMyTel)){
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>"您好，您的手机号格式不正确!"));
			else
				showErr("您好，您的手机号格式不正确!");
		}
		
		$orderMyName = trim($_REQUEST['orderMyName']);
		if(empty($orderMyName)){
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>"您好，我们需要知道您的姓名!"));
			else
				showErr("您好，我们需要知道您的姓名!");
		}
		
		if(!isset($_REQUEST['orderSex'])){
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>"您还没有选择您的性别!"));
			else
				showErr("您还没有选择您的性别!");
		}
		
		$orderSex = intval($_REQUEST['orderSex']);
		
		if(!empty($_REQUEST['orderOtherTel']))
		{
			if(!check_mobile($orderMyTel)){
				if($is_ajax==1)
					ajax_return(array("status"=>false,"message"=>"您好，您输入他人的手机号格式不正确!"));
				else
					showErr("您好，您输入他人的手机号格式不正确!");
			}
		}
		$orderOtherTel = trim($_REQUEST['orderOtherTel']);
		$orderOtherName = $_REQUEST['orderOtherName'];
		$orderOtherSex = intval($_REQUEST['orderOtherSex']);
		
		$extraServe = intval($_REQUEST['extraServe']);
		$orderReqArea = $_REQUEST['orderReqArea'];
		
		$order_time = $orderDate.$orderHour.$orderMini;
						
		$order['sid'] = $sid;
		$t_search = array('年','月','日','星期','一','二','三','四','五','六','点','分');
		$t_replace = array('','','','','','','','','','',':','');
		$order['order_time'] = to_timespan(str_replace($t_search,$t_replace,$order_time));;
		$order['order_nums'] = $orderNums;
		$order['seat_status'] = $seatStatus;
		$order['min_expense'] = $minExpense;
		$order['seat_switch'] = $seatSwitch;
		
		$order['order_tel'] = $orderMyTel;
		$order['order_name'] = $orderMyName;
		$order['order_sex'] = $orderSex;
		
		$order['order_other_tel'] = $orderOtherTel;
		$order['order_other_name'] = $orderOtherName;
		$order['order_other_sex'] = $orderOtherSex;
		
		$order['extra_serve'] = $extraServe;
		if($orderReqArea == $GLOBALS['lang']['store_order_tip'])
			$orderReqArea="";
		$order['order_msg'] = $orderReqArea;
		$order['user_id'] = intval($GLOBALS['user_info']['id']);
		$order['create_time'] = get_gmtime();
		$order['deal_type'] = $deal_type;
		
		//数据
		do
		{
			$order['order_sn'] = to_date(get_gmtime(),"Ymdhis").rand(10,99);
			$GLOBALS['db']->autoExecute(DB_PREFIX."supplier_location_order",$order,'INSERT','','SILENT'); 
			$order_id = intval($GLOBALS['db']->insert_id());
		}while($order_id==0);
		
		if($order_id > 0){
			if($is_ajax==1)
				ajax_return(array("status"=>true,"message"=>"","order_id"=>$order_id));
			else
				app_redirect(url("shop","order#view",array("order_id"=>$order_id)));
		}else{
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>"处理数据失败，请联系管理员!"));
			else
				showErr("处理数据失败，请联系管理员!");
		}
	}
	
	public function view(){
		convert_req($_REQUEST);
		$id=intval($_REQUEST['order_id']);
		
		$order = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."supplier_location_order WHERE id=".$id." AND status<>4");
		
		if(!$order){
			showErr("订单数据不存在!");
		}
		
		$order['location_name'] = $GLOBALS['db']->getOne("SELECT `name` FROM ".DB_PREFIX."supplier_location WHERE id=".$order['sid']);
		
		if($order['user_id'] != intval($GLOBALS['user_info']['id'])){
			showErr("订单数据不存在!");
		}
		
		$site_nav[] = array('name'=>$GLOBALS['lang']['HOME_PAGE'],'url'=>url("store","index"));
		if($order['deal_type'] == 1)
		{
			$order['url'] = url("store","kview",array("id"=>$id));
			$actionv = "kview";
			$ov = "ktv";
		}
		else{
			$order['url '] = url("store","view",array("id"=>$id));
			$actionv = "view";
			$ov = "ct";
		}
		$site_nav[] = array('name'=>$order['location_name'],'url'=>url("store",$actionv,array("id"=>$order['id'])));
		$site_nav[] = array('name'=>"我的订单",'url'=>url("index","uc_order#$ov"));
		
		$GLOBALS['tmpl']->assign("site_nav",$site_nav);		
		$GLOBALS['tmpl']->assign("order",$order);
		
		$GLOBALS['tmpl']->display("store_order_status.html");
	}
	
	public function modify(){
		convert_req($_REQUEST);
		$id=intval($_REQUEST['id']);
		$order = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."supplier_location_order WHERE id=".$id." AND order_time > ".get_gmtime());
		if($GLOBALS['user_info']){
			if($order['user_id']==0 || $order['user_id'] != intval($GLOBALS['user_info']['id'])){
				showErr("订单数据不存在!");
			}
		}
		else{
				showErr("请先登录!");
		}
		
		$location = $GLOBALS['db']->getRow("SELECT `name`,`no_smoking` FROM ".DB_PREFIX."supplier_location WHERE id=".$order['sid']);
		$order['location_name'] = $location['name'];
		$order['no_smoking'] = $location['no_smoking'];
		$GLOBALS['tmpl']->assign("order",$order);
		
		$week = array('日','一','二','三','四','五','六'); 
		$week = " 星期".$week[to_date($order['order_time'],"w")];
		$GLOBALS['tmpl']->assign("week",$week);
		
		$GLOBALS['tmpl']->display("store_order_modify.html");
	}
	
	public function update(){
		convert_req($_REQUEST);;
		$is_ajax = intval($_REQUEST['is_ajax']);
		
		if(!check_ipop_limit(get_client_ip(),"store_order",intval(app_conf("SUBMIT_DELAY")))){
			if($is_ajax==1)
				ajax_return(array("status"=>false,"message"=>$GLOBALS['lang']['SUBMIT_TOO_FAST']));
			else
			{
				showErr($GLOBALS['lang']['SUBMIT_TOO_FAST']);
			}
		}
		
		if($GLOBALS['user_info']){
			$id=intval($_REQUEST['id']);
			if($GLOBALS['db']->getOne("SELECT count(*) FROM ".DB_PREFIX."supplier_location_order WHERE id=".$id." AND user_id=".$GLOBALS['user_info']['id']) >0){
				$orderDate = trim($_REQUEST['orderDate']);
				if(empty($orderDate)){
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"就餐日期不能为空!"));
					else
						showErr("就餐日期不能为空!");
				}
				$orderHour = trim($_REQUEST['orderHour']);
				if(empty($orderHour)){
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"我们需要知道您具体几点就餐!"));
					else
						showErr("我们需要知道您具体几点就餐!");
				}
				$orderMini = trim($_REQUEST['orderMini']);
				if(empty($orderMini)){
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"我们需要知道您大致就餐分钟数!"));
					else
						showErr("我们需要知道您大致就餐分钟数!");
				}
				$orderNums =  intval($_REQUEST['orderNums']);
				if($orderNums == 0)
				{
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"我们需要知道有几人就餐!"));
					else
						showErr("我们需要知道有几人就餐!");
				}
				if(!isset($_REQUEST['seatStatus'])){
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"您还未选择您的座位要求!"));
					else
						showErr("您还未选择您的座位要求!");
				}
				
				$seatStatus = intval($_REQUEST['seatStatus']);
				$minExpense = trim($_REQUEST['minExpense']);
				$seatSwitch = intval($_REQUEST['seatSwitch']);
				
				$orderMyTel = trim($_REQUEST['orderMyTel']);
				
				if(empty($orderMyTel))
				{
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"您好，我们需要知道您的手机号以方便联系您!"));
					else
						showErr("您好，我们需要知道您的手机号以方便联系您!");
				}
				elseif(!check_mobile($orderMyTel)){
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"您好，您的手机号格式不正确!"));
					else
						showErr("您好，您的手机号格式不正确!");
				}
				
				$orderMyName = trim($_REQUEST['orderMyName']);
				if(empty($orderMyName)){
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"您好，我们需要知道您的姓名!"));
					else
						showErr("您好，我们需要知道您的姓名!");
				}
				
				if(!isset($_REQUEST['orderSex'])){
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"您还没有选择您的性别!"));
					else
						showErr("您还没有选择您的性别!");
				}
				
				$orderSex = intval($_REQUEST['orderSex']);
				
				if(!empty($_REQUEST['orderOtherTel']))
				{
					if(!check_mobile($orderMyTel)){
						if($is_ajax==1)
							ajax_return(array("status"=>false,"message"=>"您好，您输入他人的手机号格式不正确!"));
						else
							showErr("您好，您输入他人的手机号格式不正确!");
					}
				}
				$orderOtherTel = trim($_REQUEST['orderOtherTel']);
				$orderOtherName = $_REQUEST['orderOtherName'];
				$orderOtherSex = intval($_REQUEST['orderOtherSex']);
				
				$extraServe = intval($_REQUEST['extraServe']);
				$orderReqArea = $_REQUEST['orderReqArea'];
				
				$order_time = $orderDate.$orderHour.$orderMini;
							
				$t_search = array('年','月','日','星期','一','二','三','四','五','六','点','分');
				$t_replace = array('','','','','','','','','','',':','');
			
				$order['order_time'] = to_timespan(str_replace($t_search,$t_replace,$order_time));
				$order['order_nums'] = $orderNums;
				$order['seat_status'] = $seatStatus;
				$order['min_expense'] = $minExpense;
				$order['seat_switch'] = $seatSwitch;
				
				$order['order_tel'] = $orderMyTel;
				$order['order_name'] = $orderMyName;
				$order['order_sex'] = $orderSex;
				
				$order['order_other_tel'] = $orderOtherTel;
				$order['order_other_name'] = $orderOtherName;
				$order['order_other_sex'] = $orderOtherSex;
				
				$order['extra_serve'] = $extraServe;
				if($orderReqArea == $GLOBALS['lang']['store_order_tip'])
					$orderReqArea="";
				$order['order_msg'] = $orderReqArea;
				$order['status'] = 0;
				
				if($GLOBALS['db']->autoExecute(DB_PREFIX."supplier_location_order",$order,'UPDATE','id='.$id))
				{
					if($is_ajax==1)
						ajax_return(array("status"=>true,"message"=>"","order_id"=>$id));
					else
						app_redirect(url("shop","order#view",array("order_id"=>$id)));
				}
				else{
					if($is_ajax==1)
						ajax_return(array("status"=>false,"message"=>"处理数据失败，请联系管理员!"));
					else
						showErr("处理数据失败，请联系管理员!");
				}
			}
			else{
				if($is_ajax)
					ajax_return(array("status"=>false,"message"=>"订单数据不存在!"));
				else
					showErr("订单数据不存在!");
			}
		
		}
		else{
			if($is_ajax)
				ajax_return(array("status"=>2,"message"=>"请先登录!"));
			else
				showErr("请先登录!");
		}
	}
	
	public function del(){
		convert_req($_REQUEST);
		$id=intval($_REQUEST['id']);
		$is_ajax = intval($_REQUEST['is_ajax']);
		$order = $GLOBALS['db']->getRow("SELECT * FROM ".DB_PREFIX."supplier_location_order WHERE id=".$id);
		if($GLOBALS['user_info']){
			if($order['user_id']==0 || $order['user_id'] != intval($GLOBALS['user_info']['id'])){
				if($is_ajax)
					ajax_return(array("status"=>false,"message"=>"订单数据不存在!"));
				else
					showErr("订单数据不存在!");
			}
			else{
				$GLOBALS['db']->query("UPDATE ".DB_PREFIX."supplier_location_order SET `status` = 3 WHERE id=".$id);
				if($is_ajax)
					ajax_return(array("status"=>true,"message"=>""));
				else
					app_redirect(url("shop","order#view",array("order_id"=>$id)));
			}
		}
		else{
			if($is_ajax)
				ajax_return(array("status"=>2,"message"=>"请先登录!"));
			else
				showErr("请先登录!");
		}
	}
	
	public function seatstatus(){
		$return = array("status"=>0,"message"=>"");
		convert_req($_REQUEST);
		$now_time = get_gmtime();
		
		$order_time = trim($_REQUEST['orderDate']).trim($_REQUEST['orderHour']).trim($_REQUEST['orderMini']);
		$t_search = array('年','月','日','星期','一','二','三','四','五','六','点','分');
		$t_replace = array('','','','','','','','','','',':','');
		$order_time = str_replace($t_search,$t_replace,$order_time);
		$order_time = to_timespan($order_time);
		$deal_type = intval($_REQUEST['deal_type']);
		
		if($deal_type==0){
			if(intval($now_time) > intval($order_time)){
				$reutrn['status'] = 0 ;
				$reutrn['message'] = "您的就餐时间已经过了，请重新选择就餐时间。" ;
				ajax_return($reutrn);
				exit();
			}
		}
		
		$now_hour = to_date($now_time,"H");
		$r_hour = to_date($order_time,"H");
					
		$store_info = $GLOBALS['db']->getRow("SELECT hall,box,s_box,m_box,b_box,v_box FROM ".DB_PREFIX."supplier_location WHERE id=".intval($_REQUEST['id']));
		
		if($store_info){
			$GLOBALS['tmpl']->assign("store_info",$store_info);
			$GLOBALS['tmpl']->assign("now_hour",intval($now_hour));
			$GLOBALS['tmpl']->assign("r_hour",intval($r_hour));
			
			$GLOBALS['tmpl']->assign("seatStatus",$_REQUEST['seatStatus']);
			$GLOBALS['tmpl']->assign("minExpense",$_REQUEST['minExpense']);
			$GLOBALS['tmpl']->assign("seatSwitch",$_REQUEST['seatSwitch']);
			$GLOBALS['tmpl']->assign("deal_type",$deal_type);
			
			if($deal_type==1){
				if($store_info['s_box'] >0 || $store_info['m_box'] >0 || $store_info['b_box'] >0 || $store_info['v_box'] >0)
					$html = $GLOBALS['tmpl']->fetch("inc/store/seatstatus.html");
				else
					$html = "";
			}
			else
				$html = $GLOBALS['tmpl']->fetch("inc/store/seatstatus.html");
			$return['status']=1;
			if(intval($_REQUEST['deal_type']) == 1)
				$return['message']= "因包厢变化较快，一切以最终预订结果为准。";
			else
				$return['message']= "因餐位变化较快，一切以最终预订结果为准。";
			$return['html']= $html;
			ajax_return($return);
			exit();
		}
		else{
			$return = array("status"=>0,"message"=>"");
			ajax_return($reutrn);
			exit();
		}
	}
	
	public function inv_alert_box(){
		convert_req($_REQUEST);
		$order_id = intval($_REQUEST['order_id']);
		if($order_id==0 )
		{
			exit();
		}
		$order = $GLOBALS['db']->getRow("SELECT slo.*,sl.name as location_name,sl.address FROM ".DB_PREFIX."supplier_location_order slo LEFT JOIN ".DB_PREFIX."supplier_location sl ON sl.id=slo.sid WHERE slo.id=".$order_id." AND slo.user_id=".intval($GLOBALS['user_info']['id']));
		if($order){
			$GLOBALS['tmpl']->assign("order_id",$order_id);
			$week = array('天','一','二','三','四','五','六'); 
			$week = "周".$week[to_date($order['order_time'],"w")];
			
			$order['order_sms_tel_list'] = explode(";",$order['order_sms_tel']);
			$order['order_emall_address_list'] = explode(";",$order['order_emall_address']);
			
			$order['order_time_format'] = to_date($order['order_time'],"m月d号").$week.to_date($order['order_time'],"H点i分");
			$GLOBALS['tmpl']->assign("order",$order);
			$GLOBALS['tmpl']->assign("contacter_html",orderModule::get_contacter());
			$GLOBALS['tmpl']->display("inc/store/inv_alert_box.html");
		}
	}
	
	public function sms_email_msg(){
		convert_req($_REQUEST);
		$return = array("status"=>0,"message"=>"");
		$order_id = intval($_REQUEST['order_id']);
		if($order_id==0)
		{
			$return['status'] = 0;
			$return['message'] = "保存发送出错！";
			ajax_return($return);
		}
		
		if(!$GLOBALS['user_info']){
			$return['status'] = 0;
			$return['message'] = "请先登录!";
			ajax_return($return);
		}
		
		$order = $GLOBALS['db']->getRow("SELECT slo.*,sl.name as location_name,sl.address FROM ".DB_PREFIX."supplier_location_order slo LEFT JOIN ".DB_PREFIX."supplier_location sl ON sl.id=slo.sid WHERE slo.id=".$order_id." AND status in(0,1) AND slo.user_id=".intval($GLOBALS['user_info']['id']));
		if($order){
			$data['order_sms_tel'] = trim($_REQUEST['tel']);
			$data['order_email_address'] = trim($_REQUEST['email']);
			$data['order_sms_type'] = intval($_REQUEST['sms_type']);
			$data['order_email_type'] = trim($_REQUEST['email_type']);
			$data['order_sms_message'] = trim($_REQUEST['sms_message']);
			$data['order_email_message'] = trim($_REQUEST['email_message']);
			
			if(empty($data['order_sms_tel'])){
				$data['order_sms_message'] = "";
			}
			if(empty($data['order_email_address'])){
				$data['order_email_message'] = "";
			}
			if(!empty($data['order_sms_tel']) || !empty($data['order_email_address'])){
				$GLOBALS['db']->autoExecute(DB_PREFIX."supplier_location_order",$data,"UPDATE","id=".$order_id);
			}
			$return['status'] = 1;
			ajax_return($return);
		}
		else{
			$return['status'] = 0;
			$return['message'] = "保存发送出错！";
			ajax_return($return);
		}
	}
	
	public function get_contacter(){
		$is_ajax =intval($_REQUEST['is_ajax']);
		$is_email =intval($_REQUEST['is_email']);
		$list = array();
		$tel_num = 0;
		$email_num = 0;
		if($GLOBALS['user_info']){
			$list = $GLOBALS['db']->getAll("SELECT id,user_name,tel,email FROM ".DB_PREFIX."user_contacter WHERE user_id=".$GLOBALS['user_info']['id']);
			foreach($list as $k=>$v){
				if($v['tel']!='')
					++$tel_num;
				if($v['email']!='')
					++$email_num;		
			}
		}
		$GLOBALS['tmpl']->assign("list_count",count($list));
		$GLOBALS['tmpl']->assign("tel_count",$tel_num);
		$GLOBALS['tmpl']->assign("email_count",$email_num);
		$GLOBALS['tmpl']->assign("list",$list);
		$html = $GLOBALS['tmpl']->fetch("inc/store/inv_contacter.html");
		if($is_ajax==0){
			return $html;
		}
		else{
			echo $html;
		}
	}
	public function user_agreement(){
		$GLOBALS['tmpl']->display("store_order_user_agreement.html");
	}
}
?>